const md5 = require("md5");
import Cookies from "js-cookie";

// const APPNAME = store.state.config.shop.live_url;

const video = {
  AccessKeyId: "LTAI5t73KXvfjDLwQoq3N6da",
  BASEKEY: "erEayFbVWJSgvZLDxjKrsYjLTzKdUk&",
  BASEURL: "http://media.vi5.cn",

  // StreamName  --直播间ID       推流
  pushUrl: function(StreamName, APPNAME) {
    const pull_url = "rtmp://vidt.inexcn.cn";
    const pull_key = "W5IrZWgCXx";
    let part_url = "/" + APPNAME + "/" + StreamName;
    let time = Date.parse(new Date()) / 1000 + 30 * 60;
    let concatStr = part_url + "-" + time + "-0-0-" + pull_key;
    let md5str = md5(concatStr);
    let authKey = time + "-0-0-" + md5str;
    let final_url = pull_url + part_url + "?auth_key=" + authKey;
    return final_url;
  },

  //StreamName --直播间ID   拉流
  playUrl: function(StreamName, type, APPNAME) {
    const HOST = "vid.inexcn.cn";
    const pull_key = "mB9QTchDyZ";
    let time = Date.parse(new Date()) / 1000 + 30 * 60;
    let strRtmp =
      "/" + APPNAME + "/" + StreamName + "-" + time + "-0-0-" + pull_key;
    let strFlv =
      "/" + APPNAME + "/" + StreamName + ".flv-" + time + "-0-0-" + pull_key;
    let strm3u8 =
      "/" + APPNAME + "/" + StreamName + ".m3u8-" + time + "-0-0-" + pull_key;
    let urlRtmp = `rtmp://${HOST}/${APPNAME}/${StreamName}?auth_key=${time}-0-0-${md5(
      strRtmp
    )}`;
    let urlFlv = `http://${HOST}/${APPNAME}/${StreamName}.flv?auth_key=${time}-0-0-${md5(
      strFlv
    )}`;
    2;
    let urlm3u8 = `http://${HOST}/${APPNAME}/${StreamName}.m3u8?auth_key=${time}-0-0-${md5(
      strm3u8
    )}`;
    if (type == "rtmp") {
      return urlRtmp;
    } else if (type == "flv") {
      return urlFlv;
    } else {
      return urlm3u8;
    }
  },
};
export default video;
